var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("NotifyEventType"),
    n = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("AudioManager"),
    s = e("ModuleUI"),
    l = e("CommonHelper"),
    _ = e("Game"),
    c = e("RoleSoldierInfo"),
    d = e("ShopViewUI"),
    h = e("sdkConfig"),
    u = e("AD"),
    p = e("ActivityViewUI"),
    m = e("ChooseHeroSkillInfo"),
    f = e("choose_role_item"),
    v = e("GetZsViewUI"),
    g = e("TipViewUI"),
    y = cc._decorator,
    I = y.ccclass,
    w = y.property,
    b = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.role_item = null),
                (t.all_role_type_top = null),
                (t.all_role_list_view = null),
                (t.near_role_type_top = null),
                (t.near_role_list_view = null),
                (t.far_role_type_top = null),
                (t.far_role_list_view = null),
                (t.role_ske_node = null),
                (t.role_name_label = null),
                (t.hero_skill_info_node = null),
                (t.sure_btn_node = null),
                (t.get_btn_node = null),
                (t.left_player_view = null),
                (t.native_icon_node = null),
                (t.choose_hero_id = 0),
                (t.choose_hero_index = -1),
                (t.GameHeroList = []),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this),
                    this.showRoleListInfo(),
                    (this.choose_hero_id = 0),
                    this.showRoleSke(),
                    this.showChooseHero();
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(a.default.SEND_CHOOSE_ROLE_INDEX_INFO, this.showChooseRole, this);
            }),
            (t.prototype.OnClick = function (t) {
                e.prototype.OnClick.call(this, t);
                var o = t.node,
                    i = o.name;
                switch (i) {
                    case "back_btn":
                        if (-1 != n.GlobalParams.DungeonModeHero.value.hero.indexOf(-1))
                            return void this.uiManager.showPopup("TipViewUI", function (e) {
                                e.getComponent(g.default).showTipInfo("请先配置3名出战的英雄");
                            });
                        this.uiManager.showPopup("DungeonModeViewUI"), this.closeThisPopup();
                        break;
                    case "all_role_type_top":
                        (this.all_role_list_view.active = !this.all_role_list_view.active),
                            (o.getChildByName("image_xzyx_jt").scaleY *= -1);
                        break;
                    case "near_role_type_top":
                        (this.near_role_list_view.active = !this.near_role_list_view.active),
                            (o.getChildByName("image_xzyx_jt").scaleY *= -1);
                        break;
                    case "far_role_type_top":
                        (this.far_role_list_view.active = !this.far_role_list_view.active),
                            (o.getChildByName("image_xzyx_jt").scaleY *= -1);
                        break;
                    case "right_btn":
                        this.choose_hero_id++,
                            (this.choose_hero_id =
                                this.choose_hero_id > this.GameHeroList.length - 1 ? 0 : this.choose_hero_id),
                            this.showRoleSke();
                        break;
                    case "left_btn":
                        this.choose_hero_id--,
                            (this.choose_hero_id =
                                this.choose_hero_id < 0 ? this.GameHeroList.length - 1 : this.choose_hero_id),
                            this.showRoleSke();
                        break;
                    case "sure_btn":
                        var r = n.GlobalParams.DungeonModeHero.value,
                            s = this.GameHeroList[this.choose_hero_id],
                            _ = r.hero.indexOf(s);
                        -1 != _ && (r.hero[_] = r.hero[this.choose_hero_index]),
                            (r.hero[this.choose_hero_index] = s),
                            (n.GlobalParams.DungeonModeHero.value = r),
                            this.choose_hero_index++,
                            (this.choose_hero_index = this.choose_hero_index < 2 ? this.choose_hero_index : 2),
                            this.emitEvent(a.default.SEND_D_UPDATE_CHOOSE_HERO_INFO),
                            this.choose_hero_id++,
                            (this.choose_hero_id =
                                this.choose_hero_id > this.GameHeroList.length - 1 ? 0 : this.choose_hero_id),
                            this.showRoleSke(),
                            this.showChooseHero();
                        break;
                    case "get_btn":
                        this.buyRoleSke();
                        break;
                    case "choose_hero_0":
                    case "choose_hero_1":
                    case "choose_hero_2":
                        (this.choose_hero_index = l.default.getNameType(i, "choose_hero_")), this.showLeftHeroInfo();
                }
            }),
            (t.prototype.showRoleListInfo = function () {
                this.GameHeroList = [];
                var e = c.default.Role_info,
                    t = n.GlobalParams.playerSkinInfo.value,
                    o = [],
                    a = [];
                this.GameHeroList.push(n.GlobalParams.playerSkinInfo.value.use[0]);
                for (var i = 0; i < n.GlobalParams.GameHeroIndex.length; i++) {
                    var r = n.GlobalParams.GameHeroIndex[i];
                    -1 == t.have_hero.indexOf(r) ? a.push(r) : r != this.GameHeroList[0] && o.push(r);
                }
                for (
                    this.GameHeroList = this.GameHeroList.concat(o).concat(a), i = 0;
                    i < this.GameHeroList.length;
                    i++
                ) {
                    r = this.GameHeroList[i];
                    var s = null,
                        l = null;
                    this.all_role_list_view.children[i]
                        ? (s = this.all_role_list_view.children[i])
                        : (s = cc.instantiate(this.role_item)).setParent(this.all_role_list_view);
                    var _ = 0 == e[r].C_type ? this.near_role_list_view : this.far_role_list_view;
                    _.children[i] ? (l = _.children[i]) : (l = cc.instantiate(this.role_item)).setParent(_),
                        (s.active = !0),
                        (l.active = !0),
                        s.getComponent(f.default).showRoleInfo(e[r], r),
                        l.getComponent(f.default).showRoleInfo(e[r], r);
                }
                h.default.platform == h.EPlatform.NO_AD ||
                    u.default.getInstance().getGameTestVersion() ||
                    ((this.native_icon_node.active = !0), this.native_icon_node.setParent(this.all_role_list_view));
            }),
            (t.prototype.showChooseRole = function (e, t) {
                var o = this;
                this.choose_hero_id = this.GameHeroList.indexOf(t);
                var a = n.GlobalParams.playerSkinInfo.value;
                (this.sure_btn_node.active = -1 != a.have_hero.indexOf(this.GameHeroList[this.choose_hero_id])),
                    (this.get_btn_node.active = -1 == a.have_hero.indexOf(this.GameHeroList[this.choose_hero_id]));
                var i = _.default.shop_role_info[this.GameHeroList[this.choose_hero_id]];
                this.uiManager.getRoleSkele(i.id, function (e) {
                    (o.role_ske_node.skeletonData = e), o.role_ske_node.setAnimation(0, "battle_idle", !0);
                }),
                    (this.role_name_label.string = "" + c.default.Role_info[i.id].C_Name),
                    this.showRoleSkeBtn(),
                    this.hero_skill_info_node
                        .getComponent(m.default)
                        .getSkillInfo(this.GameHeroList[this.choose_hero_id]);
            }),
            (t.prototype.showRoleSkeBtn = function () {
                var e = _.default.shop_role_info[this.GameHeroList[this.choose_hero_id]];
                (this.get_btn_node.children[6].active = !1),
                    (this.get_btn_node.children[0].active = 0 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[1].active = 1 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[4].active = 2 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[5].active = 3 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[3].active = 4 == e.type && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[0].children[1].getComponent(cc.Label).string =
                        this.get_btn_node.children[1].children[1].getComponent(cc.Label).string =
                        "" + e.num * e.discount),
                    (this.get_btn_node.children[2].active = 1 != e.discount && !this.get_btn_node.children[6].active),
                    (this.get_btn_node.children[2].getComponent(cc.Label).string = "" + e.num);
            }),
            (t.prototype.showRoleSke = function () {
                var e = this,
                    t = n.GlobalParams.playerSkinInfo.value;
                (this.sure_btn_node.active = -1 != t.have_hero.indexOf(this.GameHeroList[this.choose_hero_id])),
                    (this.get_btn_node.active = -1 == t.have_hero.indexOf(this.GameHeroList[this.choose_hero_id])),
                    this.uiManager.getRoleSkele(this.GameHeroList[this.choose_hero_id], function (t) {
                        (e.role_ske_node.skeletonData = t), e.role_ske_node.setAnimation(0, "battle_idle", !0);
                    }),
                    (this.role_name_label.string =
                        "" + c.default.Role_info[this.GameHeroList[this.choose_hero_id]].C_Name),
                    this.emitEvent(a.default.SEND_CHOOSE_ROLE_INDEX_INFO, this.GameHeroList[this.choose_hero_id]),
                    this.hero_skill_info_node
                        .getComponent(m.default)
                        .getSkillInfo(this.GameHeroList[this.choose_hero_id]);
            }),
            (t.prototype.buyRoleSke = function () {
                var e = this,
                    t = _.default.shop_role_info[this.GameHeroList[this.choose_hero_id]],
                    o = function () {
                        var o = n.GlobalParams.playerSkinInfo.value;
                        (o.use[0] = t.id),
                            o.have_hero.push(t.id),
                            (n.GlobalParams.playerSkinInfo.value = o),
                            e.uiManager.showPopup("ObtainHeroTipView"),
                            e.emitEvent(a.default.SEND_UPDATE_CHOOSE_HERO_LIST),
                            e.showRoleSke();
                    },
                    i = n.GlobalParams.PlayerInfo.value;
                if (this.get_btn_node.children[0].active) {
                    var s = t.num * t.discount;
                    i.coin >= s
                        ? (this.uiManager.addCoinNum(-1 * s), o())
                        : this.uiManager.showPopup("ShopViewUI", function (e) {
                            e.getComponent(d.default).showShopTypeInfo("shop_coin_btn");
                        });
                } else if (this.get_btn_node.children[1].active) {
                    var l = t.num * t.discount;
                    i.zs >= l
                        ? (this.uiManager.addCoinNum(-1 * l), o())
                        : this.uiManager.showPopup("GetZsViewUI", function (e) {
                            e.getComponent(v.default).showPopupInfoView(0);
                        });
                } else
                    this.get_btn_node.children[3].active
                        ? u.default.getInstance().showVideo(function (e) {
                            r.default.playGameBGM(), e == u.ResultEnum.Success && o();
                        })
                        : this.get_btn_node.children[4].active
                            ? this.uiManager.showPopup("ActivityViewUI", function (e) {
                                e.getComponent(p.default).showActivityView(1);
                            })
                            : this.get_btn_node.children[5].active
                                ? this.uiManager.showPopup("ActivityViewUI", function (e) {
                                    e.getComponent(p.default).showActivityView(0);
                                })
                                : this.get_btn_node.children[6].active &&
                                (this.uiManager.addTykNum(-1),
                                    (n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].role_id =
                                        this.GameHeroList[this.choose_hero_id]));
            }),
            (t.prototype.showChooseHero = function () {
                for (var e = n.GlobalParams.DungeonModeHero.value, t = 0; t < 3; t++) {
                    var o = this.left_player_view.children[t],
                        a = o.children[0].children[0].getComponent(cc.Sprite);
                    if (-1 != e.hero[t]) {
                        var r = c.default.Role_info[e.hero[t]];
                        (a.spriteFrame = i.default.getInstance().getHeroHeadFrame("hero_" + r.id)),
                            (o.children[1].getComponent(cc.Label).string = r.C_Name),
                            (o.children[2].getComponent(cc.Label).string =
                                "[" + (0 == r.C_type ? "近战英雄" : "远程英雄") + "]");
                    } else
                        (a.spriteFrame = null),
                            (o.children[1].getComponent(cc.Label).string = "***********"),
                            (o.children[2].getComponent(cc.Label).string = "*****"),
                            -1 == this.choose_hero_index && (this.choose_hero_index = t);
                }
                -1 == this.choose_hero_index && (this.choose_hero_index = 0), this.showLeftHeroInfo();
            }),
            (t.prototype.showLeftHeroInfo = function () {
                for (var e = 0; e < 3; e++)
                    this.left_player_view.children[e].getComponent(cc.Sprite).enabled = this.choose_hero_index == e;
            }),
            oo([w(cc.Node)], t.prototype, "role_item", void 0),
            oo([w(cc.Node)], t.prototype, "all_role_type_top", void 0),
            oo([w(cc.Node)], t.prototype, "all_role_list_view", void 0),
            oo([w(cc.Node)], t.prototype, "near_role_type_top", void 0),
            oo([w(cc.Node)], t.prototype, "near_role_list_view", void 0),
            oo([w(cc.Node)], t.prototype, "far_role_type_top", void 0),
            oo([w(cc.Node)], t.prototype, "far_role_list_view", void 0),
            oo([w(sp.Skeleton)], t.prototype, "role_ske_node", void 0),
            oo([w(cc.Label)], t.prototype, "role_name_label", void 0),
            oo([w(cc.Node)], t.prototype, "hero_skill_info_node", void 0),
            oo([w(cc.Node)], t.prototype, "sure_btn_node", void 0),
            oo([w(cc.Node)], t.prototype, "get_btn_node", void 0),
            oo([w(cc.Node)], t.prototype, "left_player_view", void 0),
            oo([w(cc.Node)], t.prototype, "native_icon_node", void 0),
            oo([I], t)
        );
    })(s.default);
o.default = b;
